import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

// 二级路由
export const CHILDNRE_ROUTES: RouteRecordRaw[] = [
  {
    path: '/home',
    meta: {
      title: '首页',
    },
    component: () => import('../views/home/index.vue'),
  },
  {
    path: '/jiankang',
    meta: {
      title: '健康+',
    },
    component: () => import('../views/jiankang/index.vue'),
  },
  {
    path: '/shop',
    meta: {
      title: '商城',
    },
    component: () => import('../views/shop/index.vue'),
  },
  {
    path: '/zixun',
    meta: {
      title: '我的咨询',
    },
    component: () => import('../views/zixun/index.vue'),
  },
  {
    path: '/my',
    meta: {
      title: '个人中心',
    },
    component: () => import('../views/my/index.vue'),
  },
]
//  一级路由
export const ROOT_ROUTES: RouteRecordRaw[] = [
  {
    path: '/guide',
    component: () => import('../views/guide/index.vue'),
    meta: {
      title: '引导页',
    },
  },
  {
    path: '/',
    component: () => import('../views/layout/index.vue'),
    redirect: '/home',
    children: CHILDNRE_ROUTES,
  },
  {
    path: '/login',
    meta: {
      title: '登录',
    },
    component: () => import('../views/login/index.vue'),
  },
  {
    path: '/search',
    meta: {
      title: '搜索',
    },
    component: () => import('../views/search/index.vue'),
  },
  {
    path: '/listdetail/:id',
    meta: {
      title: '列表详情',
    },
    component: () => import('../views/listdetail/index.vue'),
  },
  {
    path: '/doctordetail',
    meta: {
      title: '医生详情',
    },
    component: () => import('../views/doctordetail/index.vue'),
  },
  {
    path: '/tabdoctordetail',
    meta: {
      title: 'Tab医生详情',
    },
    component: () => import('../views/tabdoctordetail/index.vue'),
  },
  {
    path: '/kepudetail',
    meta: {
      title: '专家详情',
    },
    component: () => import('../views/kepudetail/index.vue'),
  },
  {
    path: '/Doctor',
    meta: {
      title: '找医生',
    },
    component: () => import('../views/Doctor/index.vue'),
  },
  {
    path: '/deleteBing',
    meta: {
      title: '医生病例',
    },
    component: () => import('../views/deleteTobing/deleteBing.vue'),
  },
  {
    path: '/searchdoctor',
    meta: {
      title: '找医生',
    },
    component: () => import('../views/searchdoctor/index.vue'),
  },
  {
    path: '/Clinic',
    meta: {
      title: '诊所',
    },
    component: () => import('../views/Clinic/index.vue'),
  },
  {
    path: '/code',
    meta: {
      title: '验证码',
    },
    component: () => import('../views/code/index.vue')
  }, {
    path: '/Enquirefordetails',
    meta: {
      title: '咨询详情'
    },
    component: () => import('../views/Enquirefordetails/index.vue')

  },
  {
    path: '/pic',
    meta: {
      title: '账户信息',
    },
    component: () => import('../views/pic/index.vue'),
  },
  {
    path: '/pinglun',
    meta: {
      title: '评论',
    },
    component: () => import('../views/pinglun/index.vue'),
  },
  {
    path: '/update',
    meta: {
      title: '修改信息',
    },
    component: () => import('../views/update/index.vue')
  },
  {
    path: '/address',
    meta: {
      title: '地址管理'
    },
    component: () => import('../views/address/index.vue'),
  },
  {
    path: '/chun',
    meta: {
      title: '健康详情'
    },
    component: () => import('../views/chun/index.vue')
  },
  {
    path: '/cultivation',
    meta: {
      title: '8天健康养成计划'
    },
    component: () => import('../views/cultivation/index.vue')
  },
  {
    path: '/plan',
    meta: {
      title: '全部计划'
    },
    component: () => import('../views/plan/index.vue')
  },
  {
    path: '/Medic',
    meta: {
      title: '春雨医生'
    },
    component: () => import('../views/Medic/index.vue')
  },
  {
    path: '/Address_details',
    meta: {
      title: '删除'
    },
    component: () => import('../views/Address_details/index.vue')
  },
  {
    path: '/Love',
    meta: {
      title: '爱心页面'
    },
    component: () => import('../views/Love/index.vue')

  },
  {
    path: '/addressadd',
    meta: {
      title: '地址管理'
    },
    component: () => import('../views/addressadd/index.vue')
  },
  {
    path: '/MyDoctor',
    meta: {
      title: '我的医生'
    },
    component: () => import('../views/MyDoctor/MyDoctor.vue')
  },
  {
    path: '/chun',
    meta: {
      title: '健康详情'
    },
    component: () => import('../views/chun/index.vue'),
  },
  {
    path: '/Pimple',
    meta: {
      title: '21天战痘计划'
    },
    component: () => import('../views/pimple/index.vue')
  },
  {
    path: '/Sleep',
    meta: {
      title: '睡眠改善计划'
    },
    component: () => import('../views/Sleep/index.vue')
  },
  {
    path: '/Health',
    meta: {
      title: '30天上班族保健计划'
    },
    component: () => import('../views/Health/index.vue')
  },
  {
    path: '/Leg',
    meta: {
      title: '21天瘦腰计划'
    },
    component: () => import('../views/Leg/index.vue')
  },
  {
    path: '/Waist',
    meta: {
      title: '21天瘦腿计划'
    },
    component: () => import('../views/Waist/index.vue')
  },
  {
    path: '/homestead',
    meta: {
      title: '7天宅家运动计划'
    },
    component: () => import('../views/homestead/index.vue')
  },
  {
    path: '/Lose',
    meta: {
      title: '30天减肥饮食计划'
    },
    component: () => import('../views/Lose/index.vue')
  },
  {
    path: '/women',
    meta: {
      title: '30天减肥运动计划'
    },
    component: () => import('../views/women/index.vue')
  },
  {
    path: '/Todetail',
    meta: {
      title: '详情'
    },
    component: () => import('../views/Todetail/index.vue')
  },
  {
    path: '/editor',
    meta: {
      title: '档案'
    },
    component: () => import('../views/editor/index.vue')
  },
  {
    path: '/Tobingli',
    meta: {
      title: '病例夹'
    },
    component: () => import('../views/Tobingli/index.vue')
  },
  {
    path: '/edit',
    meta: {
      title: '信息编辑'
    },
    component: () => import('../views/edit/index.vue')
  },
  {
    path: '/Topi',
    meta: {
      title: '15天护肤计划'
    },
    component: () => import('../views/Topi/index.vue')
  }, {
    path: '/shoucang',
    meta: {
      title: '收藏'
    },
    component: () => import('../views/shoucang/index.vue')
  },
  {
    path: '/cultivation',
    meta: {
      title: '8天健康养成计划'
    },
    component: () => import('../views/cultivation/index.vue'),
  },
  {
    path: '/plan',
    meta: {
      title: '全部计划',
    },
    component: () => import('../views/plan/index.vue'),
  },
  {
    path: '/Address_details',
    meta: {
      title: '地址详情',
    },
    component: () => import('../views/Address_details/index.vue'),
  },
  {
    path: '/ji',
    meta: {
      title: '15天护肤计划',
    },
    component: () => import('../views/ji/index.vue'),
  },
  {
    path: '/cart',
    meta: {
      title: '购物车',
    },
    component: () => import('../views/cart/index.vue'),
  },
  {
    path: '/cartdetail',
    meta: {
      title: '购物车详情',
    },
    component: () => import('../views/cartdetail/index.vue'),
  },
  {
    path: '/order',
    meta: {
      title: '订单',
    },
    component: () => import('../views/order/index.vue'),
  },
  {
    path: '/payment',
    meta: {
      title: '支付',
    },
    component: () => import('../views/payment/index.vue'),
  },
  {
    path: '/illness',
    meta: {
      title: '疾病',
    },
    component: () => import('../views/illness/index.vue'),
  },
  {
    path: '/Parenting_knowledge',
    meta: {
      title: '育儿知识',
    },
    component: () => import('../views/Parenting_knowledge/index.vue'),
  },
  {
    path: '/Dietary_restrictions',
    meta: {
      title: '饮食宜忌',
    },
    component: () => import('../views/Dietary_restrictions/index.vue'),
  },
  {
    path: '/vaccine_time',
    meta: {
      title: '疫苗时间',
    },
    component: () => import('../views/vaccine_time/index.vue'),
  },
  {
    path: '/Growth_curve',
    meta: {
      title: '生长曲线',
    },
    component: () => import('../views/Growth_curve/index.vue'),
  },
  {
    path: '/plan',
    meta: {
      title: '全部计划'
    },
    component: () => import('../views/plan/index.vue')
  },
  // {
  //   path: '/delete',
  //   meta: {
  //     title: '删除'
  //   },
  //   component: () => import('../views/delete/index.vue')
  // },
  {
    path: '/cart',
    meta: {
      title: '购物车'
    },
    component: () => import('../views/cart/index.vue')
  },
  {
    path: '/cartdetail',
    meta: {
      title: '购物车详情'
    },
    component: () => import('../views/cartdetail/index.vue')
  },
  {
    path: '/order',
    meta: {
      title: '订单'
    },
    component: () => import('../views/order/index.vue')
  }, {
    path: '/shoucang',
    meta: {
      title: '收藏'
    },
    component: () => import('../views/shoucang/index.vue')
  },
  {
    path: '/payment',
    meta: {
      title: '支付'
    },
    component: () => import('../views/payment/index.vue')
  },
  {
    path: '/queryOrder',
    meta: {
      title: "订单查询"
    },
    component: () => import('../views/queryOrder/index.vue')
  },
  {
    path: '/parlour',
    meta: {
      title: '卖店铺'
    },
    component: () => import('../views/parlour/index.vue')
  },
  {
    path: '/word',
    meta: {
      title: '图文咨询'
    },
    component: () => import('../views/word/index.vue')
  },
  {
    path: '/phone',
    meta: {
      title: '电话咨询'
    },
    component: () => import('../views/phone/index.vue')
  },
  {
    path: '/video',
    meta: {
      title: '视频咨询'
    },
    component: () => import('../views/video/index.vue')
  },
  {
    path: '/jkdaxz',
    meta: {
      title: '健康档案跳转'
    },
    component: () => import('../views/jkdaxz/index.vue')
  }, {
    path: '/tg',
    meta: {
      title: '体重'
    },
    component: () => import('../views/tg/index.vue')
  }, {
    path: '/yd',
    meta: {
      title: '运动'
    },
    component: () => import('../views/yd/index.vue')
  },
  {
    path: '/xt',
    meta: {
      title: '血糖'
    },
    component: () => import('../views/xt/index.vue')
  },
  {
    path: '/xy',
    meta: {
      title: '血压'
    },
    component: () => import('../views/xy/index.vue')
  },
  {
    path: '/xl',
    meta: {
      title: '心率'
    },
    component: () => import('../views/xl/index.vue')
  },
  {
    path: '/sm',
    meta: {
      title: '睡眠'
    },
    component: () => import('../views/sm/index.vue')
  },
  {
    path: '/commonts',
    meta: {
      title: '咨询评论'
    },
    component: () => import('../views/commonts/index.vue')
  },{
    path: '/PatientEvaluation',
    meta: {
      title: '视频咨询'
    },
    component: () => import('../views/PatientEvaluation/index.vue')
  },
  {
    path: '/chatRoom',
    meta: {
      title: '聊天室'
    },
    component: () => import('../views/chatRoom/index.vue')
  },
  {
    path: '/parlour',
    meta: {
      title: '卖店铺'
    },
    component: () => import('../views/parlour/index.vue')
  },
  {
    path: '/jkdaxz',
    meta: {
      title: '健康档案跳转'
    },
    component: () => import('../views/jkdaxz/index.vue')
  }, {
    path: '/tg',
    meta: {
      title: '体重'
    },
    component: () => import('../views/tg/index.vue')
  }, {
    path: '/yd',
    meta: {
      title: '运动'
    },
    component: () => import('../views/yd/index.vue')
  },
  {
    path: '/xt',
    meta: {
      title: '血糖'
    },
    component: () => import('../views/xt/index.vue')
  },
  {
    path: '/xy',
    meta: {
      title: '血压'
    },
    component: () => import('../views/xy/index.vue')
  },
  {
    path: '/xl',
    meta: {
      title: '心率'
    },
    component: () => import('../views/xl/index.vue')
  },
  {
    path: '/sm',
    meta: {
      title: '睡眠'
    },
    component: () => import('../views/sm/index.vue')
  },
  {
    path: '/commonts',
    meta: {
      title: '咨询评论'
    },
    component: () => import('../views/commonts/index.vue')
  },
  {
    path: '/Handleorder',
    meta: {
      title: '视频问诊支付'
    },
    component: () => import('../views/Handleorder/index.vue')
  },
  {
    path: '/consultation',
    meta: {
      title: '视频问诊'
    },
    component: () => import('../views/consultation/index.vue')
  },
  {
    path: '/customerIndex',
    meta: {
      title: '聊天室'
    },
    component: () => import('../views/customerIndex/customerIndex.vue')
  },
    {
    path: '/VirtualLists',
    meta: {
      title: '虚拟列表'
    },
    component: () => import('../views/VirtualLists/index.vue')
  },
{
    path:'/balance',
    meta:{
      title:'余额'
    },
    component:()=>import('../views/balance/index.vue')
  },{
    path:'/finish',
    meta:{
      title:'充值完成'
    },
    component:()=>import('../views/finish/index.vue')
  },
  {
    path:'/record',
    meta:{
      title:'充值记录'
    },
    component: () => import('../views/See_more_Bloodpressure/index.vue')
  },
  {
    path: '/More_exercise',
    meta: {
      title: '更多运动'
    },
    component: () => import('../views/More_exercise/index.vue')
  },
  {
     path:'/Bloodpressureismore',
     meta:{
        title:'更多血压',
     },
      component: () => import('../views/Bloodpressureismore/index.vue')
  },{
     path:'/VirtualLists',
     meta:{
        title:'虚拟列表',
     },
      component: () => import('../views/VirtualLists/index.vue')
  },
  {
     path:'/Mychats',
     meta:{
        title:'我的聊天',
     },
      component: () => import('../views/Mychats/index.vue')
  },
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: ROOT_ROUTES,
})
const whiteList = ['/login', '/register', '/home', '/404', '/code', '/my']
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token') // 假设通过本地存储中的token来判断用户是否登录，实际可根据具体认证机制调整
  //  const tokenExpiration = parseInt(localStorage.getItem('tokenExpiration'));
  //  console.log('tokenExpiration', tokenExpiration);
   
  if (whiteList.indexOf(to.path) !== -1)  {
    // 如果要访问的路径在白名单内，直接放行
     // 如果需要认证的路由，但是没有Token或者Token已经过期，跳转到登录页面
    next()
  } else if (token) {
    // 如果有token，说明用户已登录，放行
    next()
  } else {
    // 没有token且不在白名单内，重定向到登录页
    next('/login')
  }
})



export default router
